<?php
/*
	[BuyPg] (C) 2010-2011 Buypg
	$Id: ZhuantiAction.class.php 2011-5-27 14:45:34 wufujun $
*/
if (!defined('THINK_PATH')) {
	exit('Access Denied');
}

class ZhuantiAction extends BpAction{
	
	public function index(){
		global $_SGLOBAL;
		$zhuantiid = isset ($_GET['zhuantiid']) ? intval($_GET['zhuantiid']) : 1;
		$DbZhuanTi = M('Zhuanti');
		$arrZhuanTi = $DbZhuanTi->where("zhuanti_id = $zhuantiid")->find();
		if(!$arrZhuanTi){
			$this->error('您查看的信息不存在或已经删除');
		}
		$DbSite = D('NbSite');
		$arrSite = $DbSite->getLimitSite("zhuanti_id = $zhuantiid and flag = 1","f7 DESC",2);
		
		//获取投诉分类与统计投诉数
		$DbTouSuClass = M('TousuClass');
		$arrTouSuClass = $DbTouSuClass->order("class_order desc")->select();
		$DbTouSu = M('NbTousu');
		//当前site的投诉总数
		$TouSuAmount = $DbTouSu->where("zhuanti_id = $zhuantiid")->count();
		//当前site每个投诉分类的投诉数
		foreach($arrTouSuClass as $key => $value){
			$arrTouSuClass[$key]['sum'] = $DbTouSu->where("zhuanti_id = $zhuantiid and class_id = ".$value['class_id'])->count();
		}
		
		//获取推荐网店
		$CommandSite = $DbSite->getCommendSite("zhuanti_id = $zhuantiid and flag = 1 and commend = 1","f7 DESC");
		//被诉网站
		$HeiSite = $DbSite->getLimitSite("zhuanti_id = $zhuantiid and flag = 1 and hei = 1","f7 DESC");
		//专题下的新闻
		$DbNews = M("News");
		$arrNews = $DbNews->where("zhuanti_id = $zhuantiid")->order("news_id DESC")->limit(10)->select();
		//定义左侧分类
		$LeftCate = getLeftCategory();
		//定义右侧专题列表
		$RightZT = getRightZT();
		
		//模板输出
		$this->assign('zhuantiid' , $zhuantiid);
		$this->assign('arrZhuanTi' , $arrZhuanTi);
		$this->assign('arrSite' , $arrSite[1]);
		$this->assign('leftcate' , $LeftCate);
		$this->assign('rightzt' , $RightZT);
		$this->assign('tousuamount' , $TouSuAmount);
		$this->assign('tousuclass' , $arrTouSuClass);
		$this->assign('CommandSite' , $CommandSite);
		$this->assign('HeiSite' , $HeiSite);
		$this->assign('arrNews' , $arrNews);
		$this->display();
	}
	
	public function ztlist(){
		global $_SGLOBAL;
		$zhuantiid = isset ($_GET['zhuantiid']) ? intval($_GET['zhuantiid']) : 1;
		$classid = isset ($_GET['classid']) ? intval($_GET['classid']) : 0;
		$DbZhuanTi = M('Zhuanti');
		$arrZhuanTi = $DbZhuanTi->where("zhuanti_id = $zhuantiid")->find();
		if(!$arrZhuanTi){
			$this->error('您查看的信息不存在或已经删除');
		}
		//获得专题下所有网站得分
		$DbSite = D('NbSite');
		$arrSite = $DbSite->where("flag = 1 and zhuanti_id = $zhuantiid and class_id = $classid")->select();
		$count = count($arrSite);
		$ztf1 = $ztf2 = $ztf3 = $ztf4 = $ztf5 = $ztf6 = $ztf7 = 0;
		foreach ($arrSite as $key => $value){
			$ztf1 += $arrSite[$key]['f1'];
			$ztf2 += $arrSite[$key]['f2'];
			$ztf3 += $arrSite[$key]['f3'];
			$ztf4 += $arrSite[$key]['f4'];
			$ztf5 += $arrSite[$key]['f5'];
			$ztf6 += $arrSite[$key]['f6'];
			$ztf7 += $arrSite[$key]['f7'];
			$arrSite[$key]['f7'] = formatFen($value['f7']);
		}
		$arrZhuanTi['f1_imgheight'] = round($ztf1/$count);
		$arrZhuanTi['f1'] = formatFen($arrZhuanTi['f1_imgheight']);
		$arrZhuanTi['f2_imgheight'] = round($ztf2/$count);
		$arrZhuanTi['f2'] = formatFen($arrZhuanTi['f2_imgheight']);
		$arrZhuanTi['f3_imgheight'] = round($ztf3/$count);
		$arrZhuanTi['f3'] = formatFen($arrZhuanTi['f3_imgheight']);
		$arrZhuanTi['f4_imgheight'] = round($ztf4/$count);
		$arrZhuanTi['f4'] = formatFen($arrZhuanTi['f4_imgheight']);
		$arrZhuanTi['f5_imgheight'] = round($ztf5/$count);
		$arrZhuanTi['f5'] = formatFen($arrZhuanTi['f5_imgheight']);
		$arrZhuanTi['f6_imgheight'] = round($ztf6/$count);
		$arrZhuanTi['f6'] = formatFen($arrZhuanTi['f6_imgheight']);
		$arrZhuanTi['f7_imgheight'] = round($ztf7/$count);
		$arrZhuanTi['f7'] = formatFen($arrZhuanTi['f7_imgheight']);
		
		$DbClassFen = D("ClassF");
		$arrZhuanTi['class_fen'] = $DbClassFen->getClassF($classid);
		$DbClass = M("NbClass");
		$arrClass = $DbClass->where("class_id = $classid")->find();
		
		//获取投诉分类与统计投诉数
		$DbTouSuClass = M('TousuClass');
		$arrTouSuClass = $DbTouSuClass->order("class_order desc")->select();
		$DbTouSu = M('NbTousu');
		//当前site的投诉总数
		$TouSuAmount = $DbTouSu->where("zhuanti_id = $zhuantiid")->count();
		//当前site每个投诉分类的投诉数
		foreach($arrTouSuClass as $key => $value){
			$arrTouSuClass[$key]['sum'] = $DbTouSu->where("zhuanti_id = $zhuantiid and class_id = ".$value['class_id'])->count();
		}
		
		//被诉网站
		$HeiSite = $DbSite->getLimitSite("zhuanti_id = $zhuantiid and flag = 1 and hei = 1 and class_id = $classid","f7 DESC");
		foreach ($HeiSite as $key => $value){
			$HeiSite[$key]['f7'] = formatFen($value['f7']);
		}
		//专题下的新闻
		$DbNews = M("News");
		$arrNews = $DbNews->where("zhuanti_id = $zhuantiid")->order("news_id DESC")->limit(10)->select();
		
		//定义左侧分类
		$LeftCate = getLeftCategory();
		
		//模板输出
		$this->assign('zhuantiid' , $zhuantiid);
		$this->assign('arrZhuanTi' , $arrZhuanTi);
		$this->assign('tousuamount' , $TouSuAmount);
		$this->assign('tousuclass' , $arrTouSuClass);
		$this->assign('arrClass' , $arrClass);
		$this->assign('HeiSite' , $HeiSite);
		$this->assign('arrNews' , $arrNews);
		$this->assign('arrSite' , $arrSite);
		$this->assign('leftcate' , $LeftCate);
		$this->display();
	}
}
?>
